package com.mall.service.user;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.mall.client.user.UserExtendedService;
import com.mall.custom.dao.read.UserExtendedReadMapper;
import com.mall.custom.dao.write.UserExtendedWriteMapper;
import com.mall.pojo.UserExtended;
import com.mall.pojo.UserExtendedExample;
import com.mall.pojo.UserExtendedExample.Criteria;

@Service 
public class UserExtendedServiceImpl implements UserExtendedService{
	@Autowired
	private UserExtendedReadMapper userExtendedReadMapper;
	
	@Autowired
	private UserExtendedWriteMapper userExtendedWriteMapper;

	@Override
	public UserExtended getUserExtendByUserId(Long userId) {
		UserExtendedExample example = new UserExtendedExample();
		Criteria criteria = example.createCriteria();
		criteria.andUserIdEqualTo(userId);
		List<UserExtended> userExtendedList = this.userExtendedReadMapper.selectByExample(example);
		UserExtended userExtended = null;
		if(!CollectionUtils.isEmpty(userExtendedList)){
			userExtended = userExtendedList.get(0);
		}
		return userExtended;
	}

	@Override
	public void updateExtendedByPrimaryKey(UserExtended userExtended) {
		userExtended.setGmtModify(new Date());
		this.userExtendedWriteMapper.updateByPrimaryKey(userExtended);
		
	}

	@Override
	public UserExtended getUserExtendedByUserId(Long sellerId) {
		return this.userExtendedReadMapper.selectByPrimaryKey(sellerId);
	}

}
